import 'package:ecy_app_flutter/routes/my/model/order/UserOrderItem.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'EcyImageUploadGrid.dart';

class BuildRow extends StatefulWidget {
  // const BuildRow({
  //   super.key,
  //   required this.orderItem,
  // });

  BuildRow(
      {super.key,
        this.orderItem
      }
  );

  final UserOrderItem? orderItem;

  @override
  _BuildRowState createState() => _BuildRowState(orderItem!);
}

class _BuildRowState extends State<BuildRow> {
  final UserOrderItem orderItem;

  _BuildRowState(this.orderItem);

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return buildRow(orderItem);
  }

}
Widget buildRow(UserOrderItem orderItem) {
  return Column(
    children: [
      Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            width: 80.w,
            height: 80.w,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(8.r),
              child: CachedNetworkImage(
                fit: BoxFit.cover,
                imageUrl: '${orderItem.commoditySkuImage}',
                placeholder: (context, url) => SizedBox(
                  width: 80.w,
                  height: 80.w,
                  child: Image.asset(
                    "assets/images/app_icon1024.png",
                    fit: BoxFit.cover,
                  ),
                ),
                errorWidget: (context, url, error) => SizedBox(
                  width: 80.w,
                  height: 80.w,
                  child: Image.asset(
                    "assets/images/app_icon1024.png",
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            ),
          ),
          SizedBox(width: 12.w,),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(padding: EdgeInsets.only(bottom: 6.h)),
                Text(
                  orderItem.commodityName ?? "",
                  style: TextStyle(
                    fontFamily: "PingFang SC",
                    fontWeight: FontWeight.w700,
                    fontSize: 14.sp,
                    color: const Color(0xFF262626),
                  ),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
                SizedBox(height: 4.h),
                Text(
                  orderItem.commoditySkuName ?? "",
                  style: TextStyle(
                    fontFamily: "PingFang SC",
                    fontSize: 12.sp,
                    color: const Color(0xFF8C8C8C),
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
                SizedBox(height: 8.h),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "￥${orderItem.commoditySkuTotalPrice ?? 0}",
                      style: TextStyle(
                        fontFamily: "PingFang SC",
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w700,
                        color: const Color(0xFF262626),
                      ),
                    ),
                    Text(
                      "x${orderItem.commoditySkuNum ?? 0}",
                      style: TextStyle(
                        fontFamily: "PingFang SC",
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w500,
                        color: const Color(0xFF8C8C8C),
                      ),
                    ),
                  ],
                ),

              ],
            ),
          ),

        ],
      ),
      SizedBox(height: 16.h),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "换货原因",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 14.sp,
              fontWeight: FontWeight.w700,
              color: const Color(0xFF262626),
            ),
          ),
          Text(
            "其他",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xFF8C8C8C),
            ),
          ),
        ],
      ),
      SizedBox(height: 16.h),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "补充说明",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 14.sp,
              fontWeight: FontWeight.w700,
              color: const Color(0xFF262626),
            ),
          ),
          Text(
            "与商家沟通一致后换货",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xFF8C8C8C),
            ),
          ),
        ],
      ),
      SizedBox(height: 16.h),
      // Row(
      //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
      //   children: [
      //     Text(
      //       "图片凭证",
      //       style: TextStyle(
      //         fontFamily: "PingFang SC",
      //         fontSize: 14.sp,
      //         fontWeight: FontWeight.w700,
      //         color: const Color(0xFF262626),
      //       ),
      //     ),
      //     Text(
      //       "与商家沟通一致后换货",
      //       style: TextStyle(
      //         fontFamily: "PingFang SC",
      //         fontSize: 12.sp,
      //         fontWeight: FontWeight.w500,
      //         color: const Color(0xFF8C8C8C),
      //       ),
      //     ),
      //   ],
      // ),
      ImageUploadGrid(),
      SizedBox(height: 16.h),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "创建时间",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 14.sp,
              fontWeight: FontWeight.w700,
              color: const Color(0xFF262626),
            ),
          ),
          Text(
            "2025-02-03 21:46:21",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xFF8C8C8C),
            ),
          ),
        ],
      ),
      SizedBox(height: 16.h),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "订单编号",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 14.sp,
              fontWeight: FontWeight.w700,
              color: const Color(0xFF262626),
            ),
          ),
          Text(
            "4188295047427201107 复制",
            style: TextStyle(
              fontFamily: "PingFang SC",
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xFF8C8C8C),
            ),
          ),
        ],
      ),
    ],
  );
}